# 获取新的令牌：https://help.aliyun.com/document_detail/611472.html?spm=a2c4g.2399481.0.0
from getpass import getpass
import os

from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_community.llms import Tongyi
from langchain.chains.combine_documents import create_stuff_documents_chain
from langchain_community.document_loaders import PyPDFLoader

# API KEY: sk-7a31e7bee6e8465ca00e6bdb375dc4cc
# 归属账号 1531421489726557
DASHSCOPE_API_KEY = r"sk-7a31e7bee6e8465ca00e6bdb375dc4cc"
os.environ["DASHSCOPE_API_KEY"] = DASHSCOPE_API_KEY

template = """
问题：{question}
回答：我们一步一步的思考。
"""
# 提示词 Prompt模板
prompt = ChatPromptTemplate.from_template("""
依据提供的 context内容回答问题:
<context>
{context}
</context>
Question: {input}
""")

output_parser = StrOutputParser()

# 模型 qwen-max
llm = Tongyi()

document_chain = create_stuff_documents_chain(llm, prompt)
loader = PyPDFLoader("笔记.pdf")

docs = loader.load()
question = "SVN密码"
print("正在思考问题：", question)
result = document_chain.invoke({
    "input": question,
    "context": docs
})
print("结果", result)
